/**
 * Created by json on 2016/9/28.
 */
/**
 * Created by Administrator on 2016/2/22.
 * HU = cc.Class.extend({
    jiangMj:255,				//将牌    BYTE jiangMj;								//将牌
    block:null,				//麻将块  BLOCK block[(14-2)/3];				//麻将块
});
 */
var HAND_MJ_MAX = 14;
var INVALID_CARD = 0xFF;
//麻将类型结构
var BLOCK_NULL	 = 0;				//无
var BLOCK_CHI = 1;						//吃牌结构
var BLOCK_SUN = 2;	 					//顺序结构
var BLOCK_PENG = 3;	 					//碰子结构;3个相同
var BLOCK_KE = 4;						//刻子结构;3个相同;非碰
var BLOCK_GANG = 5;						//杠子结构;4个相同
var BLOCK_AN_GANG = 6;					//暗杠
function BLOCK(){
    this.style = BLOCK_NULL;
    this.first = 0;
    return this;
}
function HU()
{
    this.jiangMj = undefined;								//将牌
    this.block = [new BLOCK(),new BLOCK(),new BLOCK(),new BLOCK()];				//麻将块
    return this;
}
//赋值 new....
var FZObj = function(obj){
    var robj = {};
    for(var i in obj){
        robj[i] = obj[i];
    }
    return robj;
};
var FZArray = function(obj){
    var arr = [];
    for(var i in obj){
        arr[i] = obj[i];
    }
    return arr;
};

mj4.MajSide=cc.Class.extend({
    seat : 255,
    Maj : null,//[14] 14个数字的数组
    Hua : null,
    block : null,//hu是一个block块
    chiMj : null,
    outMj:null,//[20] 20个数字的数组
    huMj:null,//[20] 20个数字的数组
    m_vecGuiPai : [],
    ctor : function(){
        this.seat = 255;
        this.Maj = [255,255,255,255,255,255,255,255,255,255,255,255,255,255];
        this.block = [[0,0,0],[0,0,0],[0,0,0],[0,0,0]];
        this.chiMj = [255,255,255,255];
        this.outMj = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255];
        this.huMj = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255];
        this.Init();
    },
    Init : function(){
        this.Maj = [255,255,255,255,255,255,255,255,255,255,255,255,255,255];
        this.block = [[0,0,0],[0,0,0],[0,0,0],[0,0,0]];
        this.chiMj = [255,255,255,255];
        this.outMj = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255];
        this.huMj = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255];
        this.m_vecGuiPai = [];
    },
    GetMoPai : function()
    {
        return this.Maj[14-1];
    },
    SetMoPai : function( byMoPai)
    {
        this.Maj[14-1]	=	byMoPai;
    },
    //桌面加了一张出牌
    ChuPai : function( byChuPai)
    {
        for (var byIndex = 0;byIndex < 20;byIndex++)
        {
            if (this.outMj[byIndex] == 255)
            {
                this.outMj[byIndex] = byChuPai;
                break;
            }
        }
    },
    SortCard : function(byCount,vecGuiPai)
    {
        if(vecGuiPai) {
            this.m_vecGuiPai = vecGuiPai;
        }
        if(byCount == undefined)
        {
            byCount = 13;
        }
        for(var i = 0;i < byCount - 1;i++)
        {
            for(var j = i;j < byCount;j++)
            {
                if(this.m_vecGuiPai)
                {
                    if(this.m_vecGuiPai.indexOf(this.Maj[j]) >= 0)
                    {
                        if(this.m_vecGuiPai.indexOf(this.Maj[i]) < 0)
                        {
                            var tempValue = this.Maj[i];
                            this.Maj[i] = this.Maj[j];
                            this.Maj[j] = tempValue;
                        }

                    }else if(this.m_vecGuiPai.indexOf(this.Maj[i]) < 0 && this.Maj[i] > this.Maj[j])
                    {
                        if(this.m_vecGuiPai.indexOf(this.Maj[j]) < 0) {
                            var tempValue = this.Maj[i];
                            this.Maj[i] = this.Maj[j];
                            this.Maj[j] = tempValue;
                        }
                    }
                }else{
                    var tempValue = this.Maj[i];
                    this.Maj[i] = this.Maj[j];
                    this.Maj[j] = tempValue;
                }
            }
        }
    },
    GetTotalMjCount : function()
    {
        var byHandMjCount = 0;
        for (var byIndex = 0;byIndex < 14;byIndex++)
        {
            if (this.Maj[byIndex] <= 42)
            {
                byHandMjCount++;
            }
        }
        for (var byIndex = 0;byIndex < 4;byIndex++)
        {
            if (this.block[byIndex][0] != 0)
            {
                byHandMjCount +=3;
            }
        }
        return byHandMjCount;
    },
    GetHandMjCount : function()
    {
        var byHandMjCount = 0;
        for (var byIndex = 0;byIndex < 14;byIndex++)
        {
            if (this.Maj[byIndex] <= 42)
            {
                byHandMjCount++;
            }
        }
        return byHandMjCount;
    },
    GetOutMjCount : function()
    {
        var byOutMjCount = 0;
        for (var byIndex = 0;byIndex < 20;byIndex++)
        {
            if (this.outMj[byIndex]>=0 && this.outMj[byIndex] < 34)
            {
                byOutMjCount++;
            }
        }
        return byOutMjCount;
    },
    GetBlockCount : function()
    {
        var cntCount = 0;
        for( var j=0; j<4; j++ )
        {
            if(this.block[j][0] > 0 )
            {
                cntCount++;
            }
        }
        return cntCount;
    },
    //牌被别人吃掉或者碰掉扛掉
    BeiChiPai : function()
    {
        for (var byIndex = 19;byIndex >= 0;byIndex--)
        {
            if (this.outMj[byIndex] >= 0 && this.outMj[byIndex] != 255)
            {
                this.outMj[byIndex] = 255;
                break;
            }
        }
    },
    BeiHuPai : function(byMj)
    {
        for (var byIndex = 19;byIndex >= 0;byIndex--)
        {
            if (this.outMj[byIndex] >= 0 && this.outMj[byIndex] != 255)
            {
                if(this.outMj[byIndex] == byMj)
                {
                    this.outMj[byIndex] = 255;
                }
                break;
            }
        }
    },
    //加入块到胡牌结构
    AddBlock : function( block ,byMj)
    {
        for( var i=0; i<4; i++ )
        {
            if( this.block[i][0] == 0 )
            {
                this.block[i][1] = block[1];
                this.block[i][0] = block[0];
                this.block[i][2] = block[2];

                if(byMj)
                {
                    this.chiMj[i] = byMj;
                }
                break;
            }
        }
    },
    Hu : function( byMj,byFangQiang)
    {
        for( var i=0; i<10; i++ )
        {
            if(this.huMj[i*2] == 255)
            {
                this.huMj[i*2] = byMj;
                this.huMj[i*2+1] = byFangQiang;
                break;
            }
        }
    },
    Peng : function( byMj,block ,byHandMj)
    {
        /*
        for( var i=0; i<14-1; i++ )
        {
            if( this.Maj[i] == byMj )
            {
                this.Maj[i] = 255;
                this.Maj[i+1] = 255;
                //右移3格
                break;
            }
        }
        */

        this.AddBlock(block);
        if(this.seat == 0)
        {
            if(byHandMj)
            {
                for( var i=0; i<14; i++ )
                {
                    this.Maj[i] = byHandMj[i];
                }
            }else{
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == byMj )
                    {
                        this.Maj[i] = 255;
                        this.Maj[i+1] = 255;
                        //右移3格
                        break;
                    }
                }
            }
        }else{
            var cntBlock = this.GetBlockCount();
            for( var i=0; i<14; i++ )
            {
                if(i<14-cntBlock*3)
                {
                    this.Maj[i] = 42;
                }else{
                    this.Maj[i] = 255;
                }
            }
        }

        return block;
    },
	Peng_play : function( byMj,block ,byHandMj)
    {
        /*
        for( var i=0; i<14-1; i++ )
        {
            if( this.Maj[i] == byMj )
            {
                this.Maj[i] = 255;
                this.Maj[i+1] = 255;
                //右移3格
                break;
            }
        }
        */

        this.AddBlock(block);
        if(this.seat == 0)
        {
            if(byHandMj)
            {
                for( var i=0; i<14; i++ )
                {
                    this.Maj[i] = byHandMj[i];
                }
            }else{
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == byMj )
                    {
                        this.Maj[i] = 255;
                        this.Maj[i+1] = 255;
                        //右移3格
                        break;
                    }
                }
            }
        }else{
            /*var cntBlock = this.GetBlockCount();
            for( var i=0; i<14; i++ )
            {
                if(i<14-cntBlock*3)
                {
                    this.Maj[i] = 42;
                }else{
                    this.Maj[i] = 255;
                }
            }*/
			for( var i=0; i<14-1; i++ )
			{
				if( this.Maj[i] == byMj )
				{
					this.Maj[i] = 255;
					this.Maj[i+1] = 255;
					//右移3格
					break;
				}
			}
        }

        return block;
    },
    Chi : function( byMj, ChiMode ,block,byHandMj)
    {
        /*

        */

        this.AddBlock(block,byMj);
        if(this.seat == 0)
        {
            if(byHandMj) {
                for (var i = 0; i < 14; i++) {
                    this.Maj[i] = byHandMj[i];
                }
            }else{
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == block[1] && this.Maj[i] != byMj)
                    {
                        this.Maj[i] = 255;
                        //右移3格
                        break;
                    }
                }
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == block[1]+1 && this.Maj[i] != byMj)
                    {
                        this.Maj[i] = 255;
                        //右移3格
                        break;
                    }
                }
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == block[1]+2 && this.Maj[i] != byMj)
                    {
                        this.Maj[i] = 255;
                        //右移3格
                        break;
                    }
                }
            }
        }else{
            var cntBlock = this.GetBlockCount();
            for( var i=0; i<14; i++ )
            {
                if(i<14-cntBlock*3)
                {
                    this.Maj[i] = 42;
                }else{
                    this.Maj[i] = 255;
                }
            }
        }
    },
	
	Chi_play : function( byMj, ChiMode ,block,byHandMj)
    {
        /*

        */
        this.AddBlock(block,byMj);
        if(this.seat == 0)
        {
            if(byHandMj) {
                for (var i = 0; i < 14; i++) {
                    this.Maj[i] = byHandMj[i];
                }
            }else{
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == block[1] && this.Maj[i] != byMj)
                    {
                        this.Maj[i] = 255;
                        //右移3格
                        break;
                    }
                }
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == block[1]+1 && this.Maj[i] != byMj)
                    {
                        this.Maj[i] = 255;
                        //右移3格
                        break;
                    }
                }
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == block[1]+2 && this.Maj[i] != byMj)
                    {
                        this.Maj[i] = 255;
                        //右移3格
                        break;
                    }
                }
            }
        }else{
            /*var cntBlock = this.GetBlockCount();
            for( var i=0; i<14; i++ )
            {
                if(i<14-cntBlock*3)
                {
                    this.Maj[i] = 42;
                }else{
                    this.Maj[i] = 255;
                }
            }*/
			
			if(byHandMj) {
                for (var i = 0; i < 14; i++) {
                    this.Maj[i] = byHandMj[i];
                }
            }else{
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == block[1] && this.Maj[i] != byMj)
                    {
                        this.Maj[i] = 255;
                        //右移3格
                        break;
                    }
                }
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == block[1]+1 && this.Maj[i] != byMj)
                    {
                        this.Maj[i] = 255;
                        //右移3格
                        break;
                    }
                }
                for( var i=0; i<14-1; i++ )
                {
                    if( this.Maj[i] == block[1]+2 && this.Maj[i] != byMj)
                    {
                        this.Maj[i] = 255;
                        //右移3格
                        break;
                    }
                }
            }
        }
    },

    Gang : function(byMj,byGangMode,block,byHandMj){

        /*

        */

        var bReplace = false;
        for(var i=0; i<4; i++ ) {
            //补杠
            if (this.block[i][0] == 3 ) {
                if(this.block[i][1] == byMj)
                {
                    this.block[i][0] = 5;
                    this.block[i][2] = block[2];
                    bReplace = true;
                }

            }
        }
        if(bReplace == false)
        {
            this.AddBlock(block);
        }
        if(this.seat == 0)
        {
            if(byHandMj)
            {
                for( var i=0; i<14; i++ )
                {
                    this.Maj[i] = byHandMj[i];
                }
            }else{
                for(var i=0; i<14; i++ ) {
                    if (this.Maj[i] == byMj) {
                        this.Maj[i] = 255;
                    }
                }
            }
        }else{
            var cntBlock = this.GetBlockCount();
            for( var i=0; i<14; i++ )
            {
                if(i<14-cntBlock*3)
                {
                    this.Maj[i] = 42;
                }else{
                    this.Maj[i] = 255;
                }
            }
        }
    },
	
	Gang_play : function(byMj,byGangMode,block,byHandMj){

        /*

        */

        var bReplace = false;
        for(var i=0; i<4; i++ ) {
            if (this.block[i][0] == 3 ) {
                if(this.block[i][1] == byMj)
                {
                    this.block[i][0] = 5;
                    bReplace = true;
                }

            }
        }
        if(bReplace == false)
        {
            this.AddBlock(block);
        }
        if(this.seat == 0)
        {
            if(byHandMj)
            {
                for( var i=0; i<14; i++ )
                {
                    this.Maj[i] = byHandMj[i];
                }
            }else{
                for(var i=0; i<14; i++ ) {
                    if (this.Maj[i] == byMj) {
                        this.Maj[i] = 255;
                    }
                }
            }
        }else{
            /*var cntBlock = this.GetBlockCount();
            for( var i=0; i<14; i++ )
            {
                if(i<14-cntBlock*3)
                {
                    this.Maj[i] = 42;
                }else{
                    this.Maj[i] = 255;
                }
            }*/
			for(var i=0; i<14; i++ ) {
				if (this.Maj[i] == byMj) {
					this.Maj[i] = 255;
				}
			}
        }
    },
	
//获得花猪
    GetHuaZhuColor : function()
    {
        if(this.seat == 0)
        {

            var cntWan = 0;var cntTong = 0;var cntSuo = 0;
            for(var i=0; i<4; i++ ) {
                if (this.block[i][0] > 0 ) {
                    var byMj = this.block[i][1];

                    if(byMj >= 0 && byMj<=8)
                    {
                        cntWan=13;
                    }
                    if(byMj >= 9 && byMj<=17)
                    {
                        cntTong=13;
                    }
                    if(byMj >= 18 && byMj<=26)
                    {
                        cntSuo=13;
                    }
                }
            }
            if(cntWan>=13 && cntTong>=13&&cntSuo>=13)
            {
                return 255;
            }
            if(cntWan > 0 && cntWan <= cntTong && cntWan <= cntSuo)
            {
                //万是花猪
                return 0;
            }
            if(cntTong > 0 && cntTong <= cntWan && cntTong <= cntSuo)
            {
                //筒是花猪
                return 1;
            }
            if(cntSuo > 0 && cntSuo <= cntTong && cntSuo <= cntWan)
            {
                //索是花猪
                return 2;
            }

            for(var i=0;i<this.Maj.length;i++)
            {
                var byMj = this.Maj[i];
                if(byMj >= 0 && byMj<=8)
                {
                    cntWan+=1;
                }
                if(byMj >= 9 && byMj<=17)
                {
                    cntTong+=1;
                }
                if(byMj >= 18 && byMj<=26)
                {
                    cntSuo+=1;
                }
            }
            if(cntWan>=13 && cntTong>=13&&cntSuo>=13)
            {
                return 255;
            }
            if(cntWan > 0 && cntWan <= cntTong && cntWan <= cntSuo)
            {
                //万是花猪
                return 0;
            }
            if(cntTong > 0 && cntTong <= cntWan && cntTong <= cntSuo)
            {
                //筒是花猪
                return 1;
            }
            if(cntSuo > 0 && cntSuo <= cntTong && cntSuo <= cntWan)
            {
                //索是花猪
                return 2;
            }
        }
        return 255;
    }
});
mj4.S_JieSuan_Info=cc.Class.extend({
    bZiMo : [],//;				//是否自摸
    byHuType:[],//[50];
    byWin : [] ,
    ctor : function()
    {
        this.Init();
    },
    Init : function()
    {
        this.bZiMo = [];
        this.byHuType = [];
        this.byWin = [];
    },
});

mj4.FENG_DONG = 0;
mj4.FENG_NAN = 1;
mj4.FENG_XI = 2;
mj4.FENG_BEI = 3;

mj4.MajLogic = {
    m_byZhuang:0,			//谁是庄
    m_byLianZhuang:0,		//连庄数
    m_byQuanFeng:0,			//当前局的风位
    m_byLastOutMj : 255,

    lMajSide : null,
    Feng : 0,//东南西北
    m_opRight : [],//[6]
    m_byTing : [],//[4];	//第几张牌听
    m_byHu : [],
    ctor : function()
    {
        this.Init();
    },

    Init : function(){
        this.Feng = mj4.FENG_DONG;

        this.m_byZhuang = 0;			//谁是庄
        this.m_byLianZhuang = 0;		//连庄数
        this.m_byQuanFeng = 0;			//当前局的风位

        this.lMajSide = [];
        this.lMajSide.push(new mj4.MajSide());
        this.lMajSide.push(new mj4.MajSide());
        this.lMajSide.push(new mj4.MajSide());
        this.lMajSide.push(new mj4.MajSide());

        for(var i=0;i<4;i++)
        {
            this.lMajSide[i].seat = i;
        }
        this.InitPaiJu();
    },
    InitPaiJu : function()
    {


        this.m_byLastOutMj = 255;


        this.lMajSide[0].Init();
        this.lMajSide[1].Init();
        this.lMajSide[2].Init();
        this.lMajSide[3].Init();

        this.m_byTing = [0,0,0,0];
        this.m_byHu = [0,0,0,0];
        this.m_vecGuiPai = [];




        //mj4.MajLogic.GetMajSide(0).Maj = [0,1,2,3,4,5,6,7,8,9,10,11,12,13];
    },
    SetGuiPai : function(vecGuiPai)
    {
        this.m_vecGuiPai = vecGuiPai;
    },
    SetLastOutMj : function(byOutMj)
    {
        this.m_byLastOutMj = byOutMj;
    },
    GetLastOutMj : function()
    {
        return this.m_byLastOutMj;
    },
    GetOutMjCount : function(bySeatID)
    {
        if(bySeatID < 4) {
            return this.lMajSide[bySeatID].GetOutMjCount();
        }
        return 0;
    },

    GetMajSide : function(bySeatID)
    {
        if(bySeatID < 4)
        {
            return this.lMajSide[bySeatID];
        }else{
            return null;
        }
    },
    GetBlockCount : function(bySeatID)
    {
        var cntCount = 0;
        for( var j=0; j<4; j++ )
        {
            if(this.lMajSide[bySeatID].block[j][0] > 0 )
            {
                cntCount++;
            }
        }
        return cntCount;
    },
    SortCard: function (byHandCard,byHandMjCount,vecGuiPai)// static void SortCard(BYTE byHandCard[],BYTE byHandMjCount);
    {
        if(vecGuiPai)
        {
            this.m_vecGuiPai = vecGuiPai;
        }
        if(byHandMjCount === undefined)
        {
            byHandMjCount = 13;
        }
        for(var i = 0;i < byHandMjCount - 1;i++)
        {
            for(var j = i;j < byHandMjCount;j++)
            {
                if(this.m_vecGuiPai)
                {
                    if(this.m_vecGuiPai.indexOf(byHandCard[j]) >= 0)
                    {
                        if(this.m_vecGuiPai.indexOf(byHandCard[i]) < 0) {
                            var tempValue = byHandCard[i];
                            byHandCard[i] = byHandCard[j];
                            byHandCard[j] = tempValue;
                        }
                    }else if(this.m_vecGuiPai.indexOf(byHandCard[i]) < 0 && byHandCard[i] > byHandCard[j])
                    {
                        var tempValue = byHandCard[i];
                        byHandCard[i] = byHandCard[j];
                        byHandCard[j] = tempValue;
                    }
                }else{
                    if(byHandCard[i] > byHandCard[j])
                    {
                        var tempValue = byHandCard[i];
                        byHandCard[i] = byHandCard[j];
                        byHandCard[j] = tempValue;
                    }
                }
            }
        }
        return byHandCard;
    },
    IsTongHuaSe3:function(  byMj1,  byMj2, byMj3 )
    {
        if (byMj1<=8  && byMj2<=8  && byMj3<=8)
        {
            return	true;
        }
        if (byMj1>= 9 &&byMj1<=17  && byMj2>= 9 &&byMj2<=17  && byMj3>= 9 &&byMj3<=17)
        {
            return	true;
        }
        if (byMj1>= 18 &&byMj1<=26  && byMj2>= 18 &&byMj2<=26  && byMj3>= 18 &&byMj3<=26)
        {
            return	true;
        }
        if((byMj1 == byMj2)  && (byMj2 == byMj3) && (byMj1 < 34))
        {
            return	true;
        }
        return	false;
    },
    IsTongHuaSe2:function( byMj1,  byMj2)
    {
        if (byMj1<=8  && byMj2<=8)
        {
            return	true;
        }
        if (byMj1>= 9 &&byMj1<=17  && byMj2>= 9 &&byMj2<=17)
        {
            return	true;
        }
        if (byMj1>= 18 &&byMj1<=26  && byMj2>= 18 &&byMj2<=26)
        {
            return	true;
        }
        if((byMj1 == byMj2) && (byMj1 < 34))
        {
            return	true;
        }
        return false;
    },

    GetChiXuan: function(byHandMj,byMj,chiSeq)
    {
        //风,字不能上
        if( byMj > 26)
        {
            return 0;
        }
        var chiInfo = [0,0,0];			//吃牌信息, 0-无吃牌,1-**@型, 2-*@*, 4-@**型
        var pos2 = true;var pos1 = true;var pos = true;

        for( var i=0; i<14-1; i++ )
        {
            //**@
            if( byHandMj[i] == byMj-2 && pos2 )
            {
                for( var j=i; j<14-1; j++ )
                {
                    if( byHandMj[j] == byMj-1 && this.IsTongHuaSe3(byMj,byMj-1,byMj-2))
                    {
                        //chiSeq[0] = byMj - 2;			// 吃牌类型1
                        chiInfo[0] = 1;
                        break;
                    }
                }
                pos2 = false;
            }
            //*@*
            else if( byHandMj[i] == byMj-1 )
            {
                for( var j=i; j<14-1; j++ )
                {
                    if( byHandMj[j] == byMj+1  && this.IsTongHuaSe3(byMj,byMj-1,byMj+1))
                    {
                        //chiSeq[1] = byMj - 2;			//吃牌类型2
                        chiInfo[1] = 1;
                        break;
                    }
                }
                pos1 = false;
            }
            //@**
            else if( byHandMj[i] == byMj+1)
            {
                for( var j=i; j<14-1; j++ )
                {
                    if( byHandMj[j] == byMj+2  && this.IsTongHuaSe3(byMj,byMj+1,byMj+2))
                    {
                        //chiSeq[2] = byMj;			//吃牌类型2
                        chiInfo[2] = 1;
                        break;
                    }
                }
                pos = false;
            }
        }
        if(chiInfo[0] > 0)
        {
            chiSeq[0] = byMj - 2;			// 吃牌类型1
        }
        if(chiInfo[1] > 0)
        {
            chiSeq[1] = byMj - 1;			// 吃牌类型1
        }
        if(chiInfo[2] > 0)
        {
            chiSeq[2] = byMj + 1;			// 吃牌类型1
        }
        var cntChi = 0;
        for (var i = 0;i < 3;i++)
        {
            if(chiInfo[i] > 0)
            {
                cntChi += 1;
            }
        }
        return cntChi;
    },
    /*//麻将类型结构
     enum BLOCKSTYLE
     {
     BLOCK_NULL	 = 0,				//无
     BLOCK_CHI,						//吃牌结构
     BLOCK_SUN,	 					//顺序结构
     BLOCK_PENG,	 					//碰子结构,3个相同
     BLOCK_KE,						//刻子结构,3个相同,非碰
     BLOCK_GANG,						//杠子结构,4个相同
     BLOCK_AN_GANG ,					//暗杠
     };
     vecBlock = [[0,1],[0,1],[0,1],[0,1]];//这是一个4个数组，每个数字对应一个"[类型,麻将]"结构体
     */
    GetGangXuan: function (byHandMj,vecBlock,byMj,gangSeq,bZiMo)
    {
        var byTmpHandMj = [];
        for( var j=0; j<14; j++ )
        {
            byTmpHandMj.push(byHandMj[j]);
        }
        var bZiMoGang = false;
        if(byHandMj[14-1] == 255)
        {
            byTmpHandMj[14-1] = byMj;
            bZiMoGang = false;
        }else{
            bZiMoGang = true;
        }
        this.SortCard(byTmpHandMj,14);
        var index = 0;
        for( var i=0; i<4; i++ )
        {
            for( var j=0; j<14; j++ ) {
                if (vecBlock[i][0] == 3 && vecBlock[i][1] == byTmpHandMj[j]) {
                    if (bZiMoGang == true) {
                        gangSeq[index][0] = 2;
                        gangSeq[index][1] = byTmpHandMj[j];

                        index++;
                    }
                }
            }
        }
        for( var j=0; j<=10; j++ )
        {
            if(byTmpHandMj[j+0] == byTmpHandMj[j+1] && byTmpHandMj[j+1] == byTmpHandMj[j+2] && byTmpHandMj[j+2] == byTmpHandMj[j+3] && byTmpHandMj[j+0] < 34 )
            {
                if(bZiMoGang == true){
                    gangSeq[index][0] = 4;
                }else{
                    gangSeq[index][0] = 1;
                }
                gangSeq[index][1] = byTmpHandMj[j+0];
                index++;
            }
        }
        return index;
    },
    AdjustHu_GDMJ: function(byHuType)
    {
        byHuType[mj4.HuType.TUI_DAO_HU] = 0;
        if (byHuType[mj4.HuType.QING_YI_SE])
        {
            byHuType[mj4.HuType.HUN_YI_SE]		=	0;
        }
        //大胡算番
        for (var i = 30 ;i < 50	;	i++)
        {
            if(byHuType[i] == 13)
            {
                return 13;
            };
        }
        var	iFanTotal	=	0;
        for (var i = 0 ;i < 30	;	i++)
        {
            iFanTotal	+=	byHuType[i];
        }
        if (iFanTotal	==	0)
        {
            byHuType[mj4.HuType.TUI_DAO_HU]	=	1;
            iFanTotal = 1;
        }
        return iFanTotal;
    },



};
mj4.xlchHelper = {
    GetHuanPaiSuggestion : function( byHandMj)
    {
        var ret = [];
        if(byHandMj)
        {
            for(var i = 0;i < 13 - 1;i++)
            {
                for(var j = i;j < 13;j++)
                {
                    if(byHandMj[i] > byHandMj[j])
                    {
                        var tempValue = byHandMj[i];
                        byHandMj[i] = byHandMj[j];
                        byHandMj[j] = tempValue;
                    }
                }
            }
            for(var i = 0;i < 13 - 1;i++)
            {
                if( byHandMj[i+1] - byHandMj[i] < 2)
                {
                    i=i+1;
                }else{
                    ret.push(byHandMj[i]);
                }
            }
        }
        return [];
    },
};
mj4.HuType={
    TUI_DAO_HU : 0,		LI_ZHI : 1,				SHUANG_LI_ZHI : 2,		YI_FA : 3,
    PING_HU : 4,			MEN_QING_ZI_MO : 5,		GANG_KAI : 6,			DUAN_YAO_JIU : 7,
    YI_PAI : 8,				YI_BEI_KOU : 9,			ER_BEI_KOU : 10,			QI_DUI_ZI : 11,
    DUI_DUI_HU : 12,			QUAN_DAI_YAO : 13,		HUN_DAI_YAO : 14,		HUN_LAO_TOU : 15,
    QING_YI_SE : 16,			HUN_YI_SE : 17,			YI_QI_TONG_GUAN : 18,	XIAO_SAN_YUAN : 19,
    SAN_SE_TONG_SHUN : 20,	YI_SE_SAN_SHUN : 21,		SAN_SE_TONG_KE : 22,		SAN_AN_KE : 23,
    SAN_LIAN_KE : 24,		SAN_GANG_ZI : 25,		HAI_DI_LAO_YUE : 26,		HE_DI_MO_YU : 27,
    BAO_PAI : 28,			DUI_HUA : 29,

    TIAN_HU : 30,			DI_HU : 31,				REN_HU : 32,				DA_SI_XI : 33,
    XIAO_SI_XI : 34,			DA_SAN_YUAN : 35,		ZI_YI_SE : 36,			SI_AN_KE : 37,
    SI_LIAN_KE : 38,			SI_GANG_ZI : 39,			GUO_SHI_WU_SHUANG : 40,	JIU_LIAN_BAO_DENG : 41,
    QING_LAO_TOU : 42,		LV_YI_SE : 43,			WAN_LV_YI_DIAN_HONG : 44,HONG_KONG_QUE : 45,
    BAI_WAN_SHI : 46,		DONG_BEI_XIN_GAN_XIAN : 47,DA_CHE_LUN : 48,		SHUANG_LONG_QIANG_ZHU :49
};